package cn.aitrox.ry.service.auth.dao.impl;

import cn.aitrox.ry.common.dao.MapperSqlCallback;
import cn.aitrox.ry.common.dao.impl.BaseDaoImpl;
import cn.aitrox.ry.service.auth.dao.AuthRolePermissionDao;
import cn.aitrox.ry.service.auth.entity.AuthRolePermissionEntity;
import cn.aitrox.ry.service.auth.mapper.AuthRolePermissionMapper;
import cn.aitrox.ry.util.ArrayUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class AuthRolePermissionDaoImpl extends BaseDaoImpl<AuthRolePermissionEntity> implements AuthRolePermissionDao {

    @Autowired
    private AuthRolePermissionMapper mapper;

    @Override
    public void deleteByRoleIds(List<Integer> roleIds) {
        mapper.deleteByRoleIds(roleIds);
    }

    @Override
    public void deleteByPermissionIds(List<Integer> permissionIds) {
        mapper.deleteByPermissionIds(permissionIds);
    }

    @Override
    public void batchInsert(List<AuthRolePermissionEntity> list) {
        super.batchInsert(list, 1000, new MapperSqlCallback<AuthRolePermissionEntity>() {
            @Override
            public void batchInsert(List<AuthRolePermissionEntity> objList) {
                mapper.batchInsert(objList);
            }
        });
    }

    @Override
    public void deleteByRoleIdPermissionIds(Integer roleId, List<Integer> permissionIds) {
        mapper.deleteByRoleIdPermissionIds(roleId, permissionIds);
    }

    @Override
    public List<AuthRolePermissionEntity> findByRoleIds(List<Integer> roleIds) {
        if (ArrayUtil.isEmpty(roleIds)) {
            return new ArrayList<>();
        }
        return mapper.findByRoleIds(roleIds);
    }
}
